package com.woniuxy.movie.product.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.movie.commons.core.model.Result;
import com.woniuxy.movie.product.dto.ticket.TicketInfoDto;
import com.woniuxy.movie.product.form.ticket.TicketSaledForm;
import com.woniuxy.movie.product.model.ProductTicket;
import com.woniuxy.movie.product.service.ProductTicketService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 电影票详情表 前端控制器
 * </p>
 *
 * @author 刘存益
 * @since 2023年11月17日
 */
@RestController
@RequestMapping("/productTicket")
@Api(tags = "电影票相关接口")
public class ProductTicketController {
    @Autowired
    private ProductTicketService productTicketService;

    @PostMapping("/byIds.api")
    @ApiOperation("通过多个ID查询票务数据")
    public Result<List<TicketInfoDto>> byIds(@RequestBody Set<Integer> ids){
        List<ProductTicket> productTickets = productTicketService.listByIds(ids);
        return Result.getListResult(TicketInfoDto.class).setData(BeanUtil.copyToList(productTickets,TicketInfoDto.class))
                .setMsg("查询成功");
    }

    /**
     * 通过多个ID修改票务状态为锁定状态
     * @param ids
     * @return
     */
    @PostMapping("/saveLock.api")
    @ApiOperation("修改票务状态为锁定")
    public Result<Integer> saveLock(@RequestBody Set<Integer> ids){
        Integer cont = productTicketService.saveLock(ids);
        return Result.getResult(Integer.class).setData(cont).setMsg("修改成功");
    }

    /**
     * 通过多个ID修改票务状态为已售状态以及其它信息
     * @param form
     * @return
     */
    @PostMapping("/saveSaled.api")
    @ApiOperation("修改票务信息")
    public Result<Integer> saveSaled(@RequestBody TicketSaledForm form){
        Integer cont = productTicketService.saveSaled(form);
        return Result.getResult(Integer.class).setData(cont).setMsg("修改成功");
    }

    /**
     * 通过多个ID修改票务状态为正常待售状态
     * @param ids
     * @return
     */
    @PostMapping("/saveNormal.api")
    @ApiOperation("修改票务状态为正常")
    public Result<Integer> saveNormal(@RequestBody Set<Integer> ids){
        Integer cont = productTicketService.saveNormal(ids);
        return Result.getResult(Integer.class).setData(cont).setMsg("修改成功");
    }


    
}

